package com.zzyl.controller.Iot;

import com.aliyun.iot20180120.models.*;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.AlertRuleDto;
import com.zzyl.dto.DeviceDto;
import com.zzyl.entity.Device;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description DeviceController
 * @Author huangdongye
 * @Date 2025-05-19  16:34
 */
@RestController
@RequestMapping("/iot")
public class DeviceController extends BaseController {
    @Autowired
    private DeviceService deviceService;

    /**
     * 同步产品列表
     */
    @PostMapping("/syncProductList")
    public ResponseResult syncProductList() {
        deviceService.syncProductList();
        return success();
    }

    /**
     * 获取所有产品
     *
     * @return 所有产品
     */

    @GetMapping("/allProduct")
    public ResponseResult<List<ProductVo>> allProduct() {
        List<ProductVo> result = deviceService.allProduct();
        return success(result);
    }

    /**
     * 注册设备
     *
     * @param deviceDto 设备信息
     */
    @PostMapping("/RegisterDevice")
    public ResponseResult RegisterDevice(@RequestBody DeviceDto deviceDto) {
        deviceService.RegisterDevice(deviceDto);
        return success();
    }

    /**
     * 分页查询设备
     *
     * @param page         页码
     * @param size         页大小
     * @param deviceName   设备名称
     * @param locationType 设备位置类型
     * @param productKey   产品key
     * @return 设备列表
     */
    @GetMapping("/pageQueryDevice")
    public ResponseResult<PageResponse<Device>> pageQueryDevice(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                                                @RequestParam(value = "size", defaultValue = "10") Integer size,
                                                                @RequestParam(value = "deviceName", required = false) String deviceName,
                                                                @RequestParam(value = "locationType", required = false) Integer locationType,
                                                                @RequestParam(value = "productKey", required = false) String productKey) {
        PageResponse<Device> pageResponse = deviceService.pageQueryDevice(page, size, deviceName, locationType, productKey);
        return success(pageResponse);
    }
    /**
     * 查询设备详情
     *
     * @param queryDeviceDetailRequest 查询设备详情请求
     * @return 设备详情
     */
    @PostMapping("/QueryDeviceDetail")
    public ResponseResult<DeviceVo> QueryDeviceDetail(@RequestBody QueryDeviceDetailRequest queryDeviceDetailRequest) {
        DeviceVo deviceVo = deviceService.QueryDeviceDetail(queryDeviceDetailRequest);
        return success(deviceVo);
    }
    /**
     * 查询物模型发布状态
     *
     * @param Request 查询物模型发布状态请求
     * @return 物模型发布状态
     */
    @PostMapping("/QueryThingModelPublished")
    public ResponseResult<QueryThingModelPublishedResponseBody.QueryThingModelPublishedResponseBodyData> QueryThingModelPublished(@RequestBody QueryThingModelPublishedRequest Request) {
        QueryThingModelPublishedResponseBody.QueryThingModelPublishedResponseBodyData responseBody = deviceService.QueryThingModelPublished(Request);
        return success(responseBody);
    }
    /**
     * 查询设备属性
     *
     * @param Request 查询设备属性请求
     * @return 设备属性
     */
    @PostMapping("/QueryDevicePropertyStatus")
    public ResponseResult<QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyData> QueryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest Request) {
        QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyData responseBody = deviceService.QueryDevicePropertyStatus(Request);
        return success(responseBody);
    }
    /**
     * 更新设备
     *
     * @param deviceDto 设备信息
     */
    @PostMapping("/UpdateDevice")
        public ResponseResult UpdateDevice(@RequestBody DeviceDto deviceDto) {
        deviceService.UpdateDevice(deviceDto);
        return success();
    }
    /**
     * 删除设备
     *
     */
    @DeleteMapping("/DeleteDevice")
    public ResponseResult DeleteDevice(@RequestBody DeleteDeviceRequest deleteDeviceRequest) {

        deviceService.DeleteDevice(deleteDeviceRequest);
        return success();
    }

}
